<template>
  <div>
    <div>
      <el-container>
        <el-header>
          <div style="text-align: right">
            <router-link to="/login">登陆</router-link>
            <el-divider direction="vertical" />
            <router-link to="/register">注册</router-link>
          </div>
          <h2 style="text-align: center">Lovo商城供应商系统</h2>
        </el-header>
        <el-main>
          <div style="display: flex;justify-content: center;align-items: center;height: 400px">
            <el-form
                npm
                label-width="100px"
                :model="formData"
                style="width: 400px"
                status-icon
                ref="loginForm"
                :rules="rules"
            >
              <el-form-item label="用户名" prop="userName">
                <el-input v-model="formData.userName"/>
              </el-form-item>
              <el-form-item label="密码" prop="password">
                <el-input v-model="formData.password"/>
              </el-form-item>

              <el-form-item>
                <el-button type="primary" @click="login('loginForm')">
                  登陆
                </el-button>
                <el-button @click="resetForm('loginForm')">
                  重置
                </el-button>
              </el-form-item>
            </el-form>

          </div>
        </el-main>
      </el-container>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import {ElMessage} from 'element-plus'

export default {
  data() {
    return {
      formData: {},
      rules: {
        userName: [
          {
            required: true,
            pattern: '^[0-9a-zA-Z_]{6,20}$',
            message: '用户名长度6-20位，由数字，字母，下划线组成', trigger: 'blur'
          },
        ],
        password: [
          {
            required: true,
            pattern: '^[0-9a-zA-Z_]{6,20}$',
            message: '密码长度6-20位，由数字，字母，下划线组成', trigger: 'blur'
          },
        ]
      }
    }
  },
  methods: {
    login(formName) {
      this.$refs[formName].validate((valid) => {  //开启校验
        if (valid) {   // 如果校验通过，请求接口，允许提交表单
            /*axios.get("/project/supplier/login", {
              params:this.formData
            }).then(resp => {
              if (resp.data === "ok") {
                this.$router.push("/manage/login")
              } else {
                ElMessage.error('旧密码输入错误')
              }
            })*/
          console.log(this.formData)
          }
     /*   else {   //校验不通过
          alert('不能提交');
        }*/
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style scoped>
.el-form-item{
  margin-top: 40px;
}
.el-button{
  margin-left: 50px;
}
</style>